package org.example.service;

import lombok.extern.slf4j.Slf4j;
import org.example.entity.ProductEntity;
import org.example.storage.database.ProductEntityMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Slf4j
@Component
public class ProductService {

    @Autowired
    private ProductEntityMapper productEntityMapper;

    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    public ProductEntity getProduct(Long id){
        return productEntityMapper.selectProductById(id);

    }

    @Transactional(rollbackFor = Throwable.class)
    public ProductEntity addProduct(ProductEntity productEntity){

        Integer result = productEntityMapper.addProduct(productEntity);

        if(1 == result){
            return productEntity;

        }

        return null;

    }

    @Transactional(rollbackFor = Throwable.class)
    public ProductEntity updateProduct(ProductEntity productEntity){

        Integer result = productEntityMapper.updateProduct(productEntity);

        if(1 == result){
            return productEntityMapper.selectProductById(productEntity.getId());

        }

        return null;

    }

}

// 产品
// 商品
// 商品库存

// 消费者
// 商家
